package RuMen_Demo;

import java.util.Scanner;

public class 找素数 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你查看的素数范围：");
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println("查看的素数总数为：" + search(a, b));
    }

    public static int search(int a, int b) {
        int count = 0, k = 0;
        for (int i = a; i <= b; i++) {
            boolean flag = true;
            for (int j = 2; j <= i / 2; j++) {
                if (i % j == 0) {
                    flag = false;
                    break;
                }
            }
            if (!flag) continue;
            else {
                if (k >= 0) System.out.print(i+"  ");
                if (k == 6) {
                    System.out.print("\n");
                    k = 0;
                }
                count++;
            }
        }
        return count;
    }
}
